/**
 * 内在缓冲池.
 */
export default class MemoryCache {
    private readonly cache: { [key: string]: any; } = {}
    public static readonly instance = new MemoryCache()

    public put(key: string, obj: any) {
        if (!key || !obj) {
            console.warn("你缓存了一个空对象:", key, obj)
            return
        }
        this.cache[key] = obj
    }

    public get<T>(key: string, def?: T): T {
        if (!key) {
            console.error("MemoryCache key ==null")
            return
        }
        return this.cache[key] ? this.cache[key] : def
    }

    private release() {

    }
}

class ObjRef {
    readonly obj: any
    ts: number

    constructor(obj: any) {
        this.obj = obj
        this.ts = Date.now()
    }
}